#include <iostream>
using namespace std;
  struct ListNode {
     int val;
     ListNode *next;
     ListNode() : val(0), next(nullptr) {}
     ListNode(int x) : val(x), next(nullptr) {}
     ListNode(int x, ListNode *next) : val(x), next(next) {}
 };
  class Solution {
  public:
      ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
          ListNode* dummp = new ListNode(0);
          ListNode* l3 = dummp;
          int carry = 0;
          while (l1 != nullptr || l2 != nullptr || carry != 0) {
              int val1 = l1->val;
              int val2 = l2->val;
              int sum = val1 + val2 + carry;
              carry = sum / 10;
              l3->next = new ListNode(sum % 10);
              l3 = l3->next;
              if (l1) { l1 = l1->next; }
              if (l2) { l2 = l2->next; }
          }
          return dummp->next;
      }
  };
  int main() {
      Solution sol;
      ListNode* head = new ListNode(2);
      head->next = new ListNode(4);
      head->next->next = new ListNode(3);
      ListNode* l2 = new ListNode(5, new ListNode(6, new ListNode(4)));
      ListNode*l3=sol.addTwoNumbers(head, l2);
      while (l3 != nullptr) {
          cout << l3->val ;
          l3=l3->next;
      }
      return 0;
  }